/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gameheartv2;

import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Administrator
 */
public class MyTableModel extends AbstractTableModel{

// columns name and data to show into the table


    private Vector columnNames, data;

    public MyTableModel(Vector columnNames, Vector data)
    {
    this.columnNames = columnNames;
    this.data = data;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;

    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
    if (data == null || data.size() == 0)
    return String.class;

    Vector v = (Vector)data.get(0);
    if (v == null || v.size() - 1 < columnIndex)
    return String.class;

    Object obj = ((Vector)data.get(0)).get(columnIndex);
    return obj != null ? obj.getClass() : String.class;
    }

    public int getRowCount()
    {
    return data.size();
    }

    public int getColumnCount()
    {
    return columnNames.size();
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        Object b = null;
        if(data.size() != 0)
        {
            Vector a = new Vector();
            a = (Vector) data.get(rowIndex);
            if(a.size() != 0)
            {
                b = a.get(columnIndex);
            }
        }
    return b;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Vector row = (Vector)data.get(rowIndex);
    row.set(columnIndex, aValue);
    fireTableRowsUpdated(rowIndex, rowIndex);
    }

    @Override
    public String getColumnName(int col)
    {
    return (String) columnNames.get(col);
    }


    public void isCellEditable1(int rowIndex, int columnIndex) {

    fireTableCellUpdated(data.size(), data.size());
    }

    public Vector getRow(int row) {
    return (Vector) data.get(row);
    }

    public void addRow(Vector row)
    {
        data.add(row);
        int firstRow =data.size() -1;
         int lastRow =data.size() -1;
        this.fireTableRowsInserted(firstRow, lastRow);
    }
}
